package com.study.zookeeper.curator;

import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class RecipesCyclicBarrier {

    public static CyclicBarrier barrier = new CyclicBarrier(3);

    public static void main(String[] args) {

        ExecutorService executorService = Executors.newFixedThreadPool(3);
        executorService.submit(new Thread(new Runner("1号选手")));
        executorService.submit(new Thread(new Runner("2号选手")));
        executorService.submit(new Thread(new Runner("3号选手")));
        executorService.shutdown();

    }

    static class Runner implements Runnable{

        private String name;

        public Runner(String name) {
            this.name = name;
        }

        public void run() {
            System.out.println(name + " is ready");
            try{
                RecipesCyclicBarrier.barrier.await();
            }catch (Exception e){

            }
            System.out.println(name + " 起跑！");
        }
    }
}
